@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.Authorization
@using OrchardCore.Users
@inject SignInManager<IUser> SignInManager
@inject Microsoft.AspNetCore.Authorization.IAuthorizationService authorizationService
@{ 
    var externalAuthenticationSchemes = await SignInManager.GetExternalAuthenticationSchemesAsync();
    var canAccessAdmin = await authorizationService.AuthorizeAsync(User, OrchardCore.Admin.Permissions.AccessAdminPanel);
}

@if (Context.Request.Path != "/Login" && Context.Request.Path != "/Register" && Context.Request.Path != "/ForgotPassword")
{
    <ul class="navbar-nav">
        @if (User.Identity.IsAuthenticated)
        {
            <li class="nav-item dropdown">
                <a id="user-toggle-button" href="#" class="btn btn-primary dropdown-toggle px-4 px-0" data-toggle="dropdown">
                    <i class="fa fa-user fa-fw"></i>
                    <span class="d-lg-block d-none mx-1">@User.Identity.Name</span>
                </a>
                <div class="dropdown-menu dropdown-menu-right">
                    @if(canAccessAdmin) 
                    {
                    <a class="dropdown-item" asp-route-area="OrchardCore.Admin" asp-controller="Admin" asp-action="Index"><i class="fa fa-desktop fa-fw"></i> @T["Dashboard"]</a>
                    }
                    <a class="dropdown-item" asp-route-area="OrchardCore.Users" asp-controller="Account" asp-action="ChangePassword"><i class="fa fa-lock fa-fw"></i> @T["Change Password"]</a>
                    @if (externalAuthenticationSchemes.Count() > 0)
                    {
                        <a class="dropdown-item" asp-route-area="OrchardCore.Users" asp-controller="Account" asp-action="ExternalLogins"><i class="fa fa-user-lock fa-fw"></i> @T["External Logins"]</a>
                    }
                    <form class="form-inline" asp-route-area="OrchardCore.Users" asp-controller="Account" asp-action="LogOff" method="post">
                        <button type="submit" class="btn-link navbar-btn dropdown-item">
                            <i class="fa fa-sign-out-alt fa-fw"></i> @T["Log off"]
                        </button>
                    </form>
                </div>
            </li>
        }
        else
        {
            <li class="nav-item">
                <a id="navbar-toggle-button" class="btn btn-primary px-lg-4 px-0" asp-route-area="OrchardCore.Users" asp-controller="Account" asp-action="Login">
                    <i class="fa fa-sign-in-alt fa-fw" aria-label="@T["Log in"]"></i>
                    <span class="d-lg-block d-none ml-2">@T["Log in"]</span>
                </a>
            </li>
        }
    </ul>
}